package actions;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import model.StudentDBModel;

public class SubmitFeedback extends Action {
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	{
		StudentDBModel db = new StudentDBModel();
		int reviewsCount = db.submitFeedback(request.getRemoteUser(), request.getParameter("studentID"), request.getParameter("score"), request.getParameter("comment"));
		
		if(reviewsCount < 3)
		{
			Vector<String> remainingReviewers = db.getUnassignedReviewers(request.getParameter("studentID"));
			request.setAttribute("remainingReviewers", remainingReviewers);
			request.setAttribute("studentID", request.getParameter("studentID"));
			
			return mapping.findForward("suggest");
		}
		else
		{
			
			request.setAttribute("studentID", request.getParameter("studentID"));
			return mapping.findForward("decide");
		}
		
		
	}

}
